package com.ccp.dev.im.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.poi.excel.Excel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.ccp.dev.im.dao.ImRoomMsgStatusDao;
import com.ccp.dev.im.model.ImRoomMsgStatus;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;


/**
 * im_room_msg_status 信息操作服务类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ImRoomMsgStatusService extends BaseService<ImRoomMsgStatus> {

    @Resource
    private ImRoomMsgStatusDao dao;

    public HSSFWorkbook exportExcel(Excel excel,QueryFilter queryFilter){
    List<ImRoomMsgStatus> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (ImRoomMsgStatus data : dataList) {
        excel.cell(startRow, 0).value(data.getRoomId());
        //excel.cell(startRow, 1).value(data.getMc());
        //可在赋值时，根据需求进行格式化
        //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
        //excel.cell(startRow, 3).value(data.getSj());
        //excel.cell(startRow, 4).value(data.getTenantId());
        startRow++;
        }
        return excel.getWorkBook();
    }

    /**
     * 根据用户id以及群组id删除数据
     * @param userId 用户id
     * @param roomId 群组id
     */
    public void delByRoomIdAndUserId (String roomId , String userId){
        Map<String , String> map = new HashMap();
        map.put("userId",userId);
        map.put("roomId",roomId);
        dao.delByRoomIdAndUserId(map);
    }
    /**
     * 根据用户id以及群组id删除数据
     * @param userId 用户id
     * @param roomId 群组id
     */
    public ImRoomMsgStatus getByRoomIdAndUserId (String roomId , String userId){
        Map<String , String> map = new HashMap();
        map.put("userId",userId);
        map.put("roomId",roomId);
        return  dao.getByRoomIdAndUserId(map);
    }

}
